 /*
 * @description: 精英收入统计
 * @Author: along
 * @Date: 2021-06-05
 * @Last Modified by: along
 * @Last Modified time: 2021-06-05
 */
<template>
    <div class="socialClassDetail">
        <div class="content-wrapper">

            <!-- header -->
            <div class="header">
                <div class="header-title">
                    收入总计
                    <p class="header_name">
                        校园精英：{{ formData.true_name }}-{{ formData.phone }}
                    </p>
                </div>
            </div>

            <!-- info-->
            <div class="__info">
                <div class="__info_wrap">
                    <p class="__info_title">实际到账时间</p>
                    <el-date-picker
                        v-model="date"
                        type="datetimerange"
                        :picker-options="pickerOptions()"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        align="right"
                        size="small"
                        @change="getInconm()"
                    />
                </div>
                <div class="__info_price">
                    <div class="__info_items">
                        <div class="__info_items__inner">
                            <div class="__info_items-title">商城佣金</div>
                            <div class="__info_items-value">¥{{ total.shop_total_income | filterMoney }}</div>
                        </div>
                    </div>
                    <div class="__info_items">
                        <div class="__info_items__inner">
                            <div class="__info_items-title">精英PK赛奖金</div>
                            <div class="__info_items-value">¥{{ total.pk_total_income | filterMoney }}</div>
                        </div>
                    </div>
                    <div class="__info_items">
                        <div class="__info_items__inner">
                            <div class="__info_items-title">任务收益</div>
                            <div class="__info_items-value">¥{{ total.task_total_income | filterMoney }}</div>
                        </div>
                    </div>
                    <div class="__info_items">
                        <div class="__info_items__inner">
                            <div class="__info_items-title">线下任务收益</div>
                            <div class="__info_items-value">¥{{ total.offline_task_total_income | filterMoney }}</div>
                        </div>
                    </div>
                    <div class="__info_items">
                        <div class="__info_items__inner">
                            <div class="__info_items-title">一卡通推荐收益</div>
                            <div class="__info_items-value">¥{{ total.invite_vip_total_income | filterMoney }}</div>
                        </div>
                    </div>
                    <!--<div class="__info_items">
                        <div class="__info_items__inner">
                            <div class="__info_items-title">邀请有礼奖励</div>
                            <div class="__info_items-value">¥{{ total.invite_new_user_total_income | filterMoney }}</div>
                        </div>
                    </div>-->
                    <div class="__info_items">
                        <div class="__info_items__inner">
                            <div class="__info_items-title">平台分红</div>
                            <div class="__info_items-value">¥{{ total.rebate_official_total_income | filterMoney }}</div>
                        </div>
                    </div>
                    <div class="__info_items">
                        <div class="__info_items__inner">
                            <div class="__info_items-title">其他收益</div>
                            <div class="__info_items-value">¥{{ total.other_total_income | filterMoney }}</div>
                        </div>
                    </div>
                    <div class="__info_items">
                        <div class="__info_items__inner no-border">
                            <div class="__info_items-title">系统扣款</div>
                            <div class="__info_items-value green">¥{{ total.total_deduct_income | filterMoney }}</div>
                        </div>
                    </div>
                    <div class="__info_items total">
                        <div class="__info_items__inner no-border">
                            <div class="__info_items-title">所有收入总计</div>
                            <div class="__info_items-value orange">¥{{ total.total_income | filterMoney }}</div>
                        </div>
                    </div>
                </div>
            </div>
            <div :style="{width: '100%', minHeight: '12px', background: 'rgba(240,242,245,1)'}"/>

            <!-- 任务状态 -->
            <div class="__tab">
                <div
                    v-for="(el,index) in ['商城佣金', '精英PK赛奖金', '任务收益', '线下任务收益', '一卡通推荐收益', '平台分红', '其他收益', '系统扣款']"
                    :key="index"
                    class="__tab_items"
                    @click="handleChangeTabPos(index)"
                >
                    <p
                        :style="{
                            color: STEP == index ? 'rgba(32, 160, 255, 1)' : 'rgba(102, 102, 102, 1)',
                            fontWeight: STEP == index ? 500 : 400
                        }"
                        class="__tab_items_text"
                    >
                        {{ el }}
                    </p>
                </div>
                <div
                    :style="{width: tabObj.width + 'px', left: tabObj.left + 'px'}"
                    class="__tab_lines"
                />
            </div>

            <!-- 商城佣金 -->
            <student-commission-first
                v-if="STEP === 0"
                :agent_no="agent_no"
                :start_time="Number(start_time)"
                :end_time="Number(end_time)"
                :shop_total_income="total.shop_total_income"
                ref="studentCommissionFirst"
            />

            <!-- 精英pk赛奖金 -->
            <student-commission-second
                v-if="STEP === 1"
                :agent_no="agent_no"
                :start_time="Number(start_time)"
                :end_time="Number(end_time)"
                :pk_total_income="total.pk_total_income"
                ref="studentCommissionSecond"
            />

            <!-- 任务收益 -->
            <student-commission-thrid
                v-if="STEP === 2"
                :agent_no="agent_no"
                :start_time="Number(start_time)"
                :end_time="Number(end_time)"
                :task_total_income="total.task_total_income"
                ref="studentCommissionThrid"
            />

            <!-- 线下任务收益 -->
            <student-commission-thrid-offline
                v-if="STEP === 3"
                :agent_no="agent_no"
                :start_time="Number(start_time)"
                :end_time="Number(end_time)"
                :offline_task_total_income="total.offline_task_total_income"
                ref="studentCommissionThridOffline"
            />
            <!-- 一卡通推荐收益 -->
            <student-commission-vip
                v-if="STEP === 4"
                :agent_no="agent_no"
                :start_time="Number(start_time)"
                :end_time="Number(end_time)"
                :total_income="total.invite_vip_total_income"
                ref="studentCommissionVip"
            />
            <!-- 邀请有礼奖励收益 -->
            <!--<student-commission-invitation
                v-if="STEP === 5"
                :agent_no="agent_no"
                :start_time="Number(start_time)"
                :end_time="Number(end_time)"
                :total_income="total.invite_new_user_total_income"
                ref="studentCommissionInvitation"
            />-->
            <!-- 平台分红 -->
            <student-commission-bonus
                v-if="STEP === 5"
                :agent_no="agent_no"
                :start_time="Number(start_time)"
                :end_time="Number(end_time)"
                :total_income="total.rebate_official_total_income"
                ref="studentCommissionInvitation"
            />
            <!-- 其他收益 -->
            <student-commission-others
                v-if="STEP === 6"
                :agent_no="agent_no"
                :start_time="Number(start_time)"
                :end_time="Number(end_time)"
                :total_income="total.other_total_income"
                ref="studentCommissionOthers"
            />
            <!-- 平台扣款 -->
            <student-commission-withhold
                v-if="STEP === 7"
                :agent_no="agent_no"
                :start_time="Number(start_time)"
                :end_time="Number(end_time)"
                :total_income="total.total_deduct_income"
                ref="studentCommissionOthers"
            />
        </div>
    </div>
</template>

<script>
import {back} from '@/mixin/back';
import studentCommissionFirst from '@/components/student/student-commission-first.vue';
import studentCommissionSecond from '@/components/student/student-commission-second.vue';
import studentCommissionThrid from '@/components/student/student-commission-thrid.vue';
import studentCommissionThridOffline from '@/components/student/student-commission-thrid-offline.vue';
import StudentCommissionVip from "@/components/student/student-commission-vip";
import StudentCommissionInvitation from "@/components/student/student-commission-invitation";
import StudentCommissionOthers from "@/components/student/student-commission-others";
import StudentCommissionWithhold from "@/components/student/student-commission-withhold";
import StudentCommissionBonus from "@/components/student/student-commission-bonus";
export default {
    mixins: [back],
    components: {
        StudentCommissionBonus,
        StudentCommissionWithhold,
        StudentCommissionOthers,
        StudentCommissionInvitation,
        StudentCommissionVip,
        studentCommissionFirst,
        studentCommissionSecond,
        studentCommissionThrid,
        studentCommissionThridOffline
    },
    data() {
        return {
            STEP: 0, //0:商城佣金 1:精英PK赛奖金 2:任务收益
            agent_no: '',
            loading: false,
            date: [],//实际到账时间
            tabObj: {
                width: 52,
                left: 25
            },
            formData: {
                true_name: '',
                phone: ''
            },
            authResult: {},
            total: {
                total_income: 0,
                pk_total_income: 0,
                task_total_income: 0,
                offline_task_total_income: 0,
                shop_total_income: 0,
                invite_vip_total_income: 0,
                invite_new_user_total_income: 0,
                other_total_income: 0,
                rebate_official_total_income: 0,
                total_deduct_income: 0
            }
        };
    },
    computed: {
        start_time () {
            return this.date === null ? '' : (this.date.length === 0 ? '' : (Date.parse(new Date(this.date[0]))) / 1000);
        },
        end_time () {
            return this.date === null ? '' : (this.date.length === 0 ? '' : (Date.parse(new Date(this.date[1]))) / 1000);
        }
    },
    filters: {
        filterMoney (val) {
            if(val) return val.toFixed(2);
            return '0.00';
        }
    },
    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '掌大精英'}, {title: '掌大精英数据', path: '/student/student-data'}, {title: '收入总计'}]);
        this.authResult = this.$route.meta.authResult;
        this.agent_no = this.$route.query.agent_no;
        this.formData = {
            true_name: this.$route.query.true_name,
            phone: this.$route.query.phone,
        };
        this.getInfo();

        setTimeout(() => {
            if(!document.querySelectorAll('.__tab_items')[this.cuurentTabIndex]) return false;

            const rectsDom = document.querySelectorAll('.__tab_items')[this.cuurentTabIndex].getClientRects()[0];

            this.$set(this.tabObj, 'width', parseInt(rectsDom.width));
            this.$set(this.tabObj, 'left', parseInt(rectsDom.left - 240));
        },100);
    },
    methods: {
        /**
         * @description 获取统计数据
         */
        getInfo() {
            this.loading = true;
            this.$post('/student/stuagent_rebate%5Cget_total_income', {
                agent_no: this.agent_no,
                start_time: this.start_time,
                end_time: this.end_time
            }, resp => {
                if (resp.code === 1) {
                    this.total = {
                        ...resp.data
                    };
                    this.loading = false;
                } else {
                    this.$notify({
                        title: '失败',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },

        getInconm () {
            this.getInfo();
        },

        /**
         * @description 佣金类型切换
         */
        handleChangeTabPos (index) {
            this.STEP = index;

            if(!document.querySelectorAll('.__tab_items')[index]) return false;

            const rectsDom = document.querySelectorAll('.__tab_items')[index].getClientRects()[0];

            this.$set(this.tabObj, 'width', parseInt(rectsDom.width));
            this.$set(this.tabObj, 'left', parseInt(rectsDom.left - 222));

            // TODO
        },

        /**
         * @description 时间处理
         */
        pickerOptions () {
            return {
                shortcuts : [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();

                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();

                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();

                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            };
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style scoped lang="less">
.socialClassDetail {
    width: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    box-sizing: border-box;
    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;
    }

    .__zsdx_wrap {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        .__top {
            display: flex;
            align-items: center;
            .__top_name {
                color: rgba(51, 51, 51, 1);
                font-size: 14px;
                font-weight: 500;
                margin-right: 6px;
            }
            .__top_logo {
                width: 28px;
                height: 14px;
            }
        }
        .__phone {
            height: 20px;
            color: rgba(153, 153, 153, 1);
            font-size: 14px;
            line-height: 20px;
            margin-top: 7px;
            margin-bottom: 5px;
        }
        .__id {
            height: 20px;
            color: rgba(153, 153, 153, 1);
            font-size: 14px;
            line-height: 20px;
        }
    }

    /*header*/

    .header {
        height: 68px;
        padding: 24px;
        box-sizing: border-box;
        box-shadow: 0px -1px 0px 0px #F0F2F5;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1px solid #F0F2F5;

        .header-title {
            color: #333333;
            font-size: 18px;
            height: 20px;
            font-weight: 500;
            position: relative;
            margin: 24px 0 24px 12px;
            display: flex;
            &::before {
                content: '';
                position: absolute;
                left: -8px;
                top: -1px;
                width: 3px;
                height: 18px;
                background: #1890FF;
            }
            .header_name {
                color: rgba(47, 189, 179, 1);
                font-size: 14px;
                height: 20px;
                line-height: 20px;
                margin-left: 12px;
                font-weight: 500;
                margin-top: 1px;
            }
        }
    }

    .__info {
        width: calc(100% - 64px);
        margin: 24px 32px;
        .__info_wrap {
            width: 100%;
            height: 36px;
            display: flex;
            align-items: center;
            margin-bottom: 18px;
            .__info_title {
                color: rgba(51, 51, 51, 1);
                font-size: 14px;
                margin-right: 12px;
            }
        }
        .__info_price {
            height: 88px;
            background: #FEF7F3;
            border-radius: 4px;
            display: flex;
            align-items: center;
            .__info_items {
                height: 100%;
                flex: 1;
                display: flex;
                align-items: center;
                justify-content: center;
                &.total {
                    background: #FFE4D6;
                    border-radius: 0 4px 4px 0;
                }
                &__inner {
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    height: 40px;
                    width: 100%;
                    border-right: 1px solid #E4DAD4;
                    padding: 0 34px;
                    &.no-border {
                        border: 0;
                    }
                }
                &-title {
                    font-size: 14px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #333333;
                    margin-bottom: 12px;
                }
                &-value {
                    font-size: 16px;
                    font-family: PingFangSC-Medium, PingFang SC;
                    font-weight: 500;
                    color: #333333;
                    &.green {
                        color: #2FBDB3;
                    }
                    &.orange {
                        color: #FF8E39;
                    }
                }
            }
        }
    }

    .__tab {
        width: 100%;
        height: 53px;
        display: flex;
        align-items: center;
        box-sizing: border-box;
        padding-left: 24px;
        border-bottom: 1px rgba(235, 238, 245, 1) solid;
        position: relative;
        .__tab_items {
            height: 53px;
            display: flex;
            align-items: center;
            cursor: pointer;
            margin-right: 32px;
            .__tab_items_text {
                font-size: 14px;
                white-space: nowrap;
                letter-spacing: 0;
                font-weight: 500;
            }
        }
        .__tab_lines {
            position: absolute;
            height: 2px;
            background: rgba(32, 160, 255, 1);
            transition: all .2s linear;
            bottom: 0;
        }
        .__tab_desc {
            color: rgba(255, 142, 57, 1);
            font-size: 12px;
            white-space: nowrap;
            position: absolute;
            right: 32px;
        }
    }

    .btn-view {
        height: 48px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 24px 24px 0;
    }

    .cursor_font {
        color: rgba(24, 144, 255, 1);
        cursor: pointer;
    }

    /*筛选*/

    .filter-view {
        margin: 24px 0;
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        margin-bottom: 0px;
        .header-new-box {
            display: flex;
            align-items: center;
            color: #606266;
            white-space: nowrap;
            margin-left: 32px;
            margin-bottom: 24px;
            &-title {
                margin-right: 12px;
                white-space: nowrap;
            }
            .header-button {
                width: 84px;
                height: 36px;
                border: 1px rgba(24, 144, 255, 1) solid;
                border-radius: 4px;
                text-align: center;
                line-height: 36px;
                color: rgba(24, 144, 255, 1);
                font-size: 14px;
                font-weight: 500;
                cursor: pointer;
            }
            .header-rest {
                color: rgba(24, 144, 255, 1);
                font-size: 14px;
                cursor: pointer;
                font-weight: 500;
                &:hover {
                    text-decoration: underline;
                }
            }
        }
    }

    .status-wrapper {
        display: flex;
        align-items: center;

        .status-dot {
            width: 6px;
            height: 6px;
            border-radius: 50%;
            margin-right: 5px;

            &.success {
                background: #4CD964;
            }

            &.danger {
                background: #FF3030;
            }

            &.warning {
                background: #FFA72D;
            }

            &.normal {
                background: #C2C2C2;
            }
        }
    }

    /* 分页 */

    .pagination-wrapper {
        padding: 10px 32px;

        .el-pagination {
            float: right;
            padding: 0;
            background-color: transparent;
        }
    }

    .text-button {
        width: 180px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        text-align: left;
    }
    // 表格
    .data-table {
        ::-webkit-scrollbar {
            width: 6px;
            height: 6px;
        }
        // 操作按钮
        .option-btn-group {
            .el-button {
                margin-left: 0;
                margin-right: 10px;
            }
        }
    }

    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    .dialog-footer {
        display: flex;
        justify-content: center;
    }
    /deep/ .el-table__fixed-right {
        right: 6px!important;
    }

    .el-popover-hover {
      border: none;
      background: transparent !important;
      border: none;
      outline: none;
      margin-left: -20px;
  }
}
</style>

<style lang="less">
.socialClassDetail {
    .el-icon-question {
        color: rgba(0, 0, 0, 0.3);
        margin-left: 2px;
    }
    .el-table .caret-wrapper {
        top: -1px;
    }
    .__title {
        color: rgba(51, 51, 51, 1);
        font-weight: 500;
    }
    .has-gutter {
        th .cell {
            color: rgba(51, 51, 51, 1);
            font-weight: 500;
        }
    }
    .el-dialog__header {
        padding-top: 10px;
        box-shadow:0px 1px 0px 0px rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    .el-dialog__body {
        padding-left: 32px;
        padding-right: 32px;
    }
    .__model {
        .el-table__body-wrapper {
            height: auto !important;
        }
    }
}

.clearfixNew {
    .btn-prev, .btn-next {
        background-color: transparent !important;
    }
    .el-pager .active {
        background-color: transparent !important;
        color: #20A0FF !important;
    }
    .el-pager .number {
        background-color: transparent !important;
        color: #606266;
    }
    .el-pagination__jump {
        margin-left: 20px;
    }
}
.zd-popper-class {
    text-align: left !important;
}
</style>
